package com.kaizige.realtor.Controller;

import com.kaizige.realtor.Dao.houseMsgDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class deleteController {
	@Autowired
	houseMsgDao hmd;
	@GetMapping("/ownDelete")
	public String toOwnDelete(Model model, HttpSession session){
		List<Map<String, Object>> mapList = hmd.queryHmByOwner((String)session.getAttribute("LoginUser"));
		model.addAttribute("houses",mapList);
		return "/crud/ownDelete";
	}
	
	@PostMapping("/ownDelete")
	public String ownDelete(@RequestParam("id")int id){
		hmd.delHouByID(id);
		return "redirect:/ownIndex";
	}
}